package com.oocl.shopping.controller;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.oocl.shopping.repository.BooksDB;
import com.oocl.shopping.service.BookService;
import com.oocl.shopping.service.impl.BookServiceImpl;

/**
 * Servlet implementation class InitServlet
 */
public class InitServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
    private BookService bookService;   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InitServlet() {
    	
    }

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		bookService = new BookServiceImpl();
    	BooksDB.setBooksMap(bookService.findAll());
		//test
		System.out.println("系统已有图书");
		for(String name:BooksDB.getBooksMap().keySet()){
			System.out.println(name);
		}
		
		System.out.println(getServletContext());
		getServletContext().setAttribute("books", BooksDB.getBooksMap());
	}

    
    
}
